package reading.util.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.util.Collection;

/**
 * @author yangbajing(yangbajing @ gmail.com) on 2016-08-31.
 */
public class Utils {


    public static String fileSha256(byte[] bytes) {
        return DigestUtils.sha256Hex(bytes);
    }

    public static <T> String collectionJoinString(Collection<T> list) {
        return collectionJoinString(list, ",");
    }

    public static <T> String collectionJoinString(Collection<T> list, CharSequence sep) {
        StringBuilder sb = new StringBuilder();
        boolean start = true;
        for (T item : list) {
            if (start) {
                sb.append(item);
                start = false;
            } else {
                sb.append(sep);
                sb.append(item);
            }
        }
        return sb.toString();
    }

}
